/*
 * Copyright 2008 [rapid-framework], Inc. All rights reserved.
 * Website: http://www.rapid-framework.org.cn
 */

    define("pages/jls_Zpwh/form", [
            '../../pages/jls_Zpwh/ZpwhForm.html.js',
        ],
        function(require){
            var _show=function(_ryjbxx,_zpwh,findZpwh){
                var tmp= require("../../pages/jls_Zpwh/ZpwhForm.html");
                var htmlcompile = template.compile(tmp);
                var html = htmlcompile(
                    {
                        title:"照片维护",
                        jbxx:_ryjbxx,
                        data:_zpwh,
                    });
                $("#gjcx").dialog('destroy')
                $("#dlgZpwh").dialog('destroy')
                $("#zpwhForm").html(html);
                $.parser.parse($("#zpwhForm").parent());
                $('#dlgZpwh').window('open');
                bindAction(findZpwh);
            }

            var submitZpwh=function(findZpwh){
                var row = $('#jbxxId').datagrid('getSelected');
                var validate=$("#dlgZpwh").form('validate');
                if (validate) {
                    var data =$("#fm").serialize()+"&jsbh="+row.jsbh+"&rybh="+row.rybh;
                    submitLoad();
                    $.ajax({
                        type : "POST",  //提交方式
                        url : "/jls_zpwh/zpwhAdd",//路径
                        data : data,//数据，这里使用的是Json格式进行传输
                        success : function(result) {
                            if (result.success) {
                                if($.isFunction(findZpwh)){
                                    findZpwh();
                                }
                                $.messager.alert("确定","保存成功","info");
                                javascript:$('#dlgZpwh').dialog('close');
                                removeLoad();
                            }else{
                                $.messager.alert("确定","保存失败","info");
                                removeLoad();
                            }
                        },
                        error:function(){
                            removeLoad();

                        }
                    });
                }else{
                    $.messager.alert("提示", '必填项不能为空！');
                }
            };
            var updateZpwh=function(findZpwh){
                var row = $('#jbxxId').datagrid('getSelected');
                var validate=$("#dlgZpwh").form('validate');
                if (validate) {
                    var data =$("#fm").serialize();
                    submitLoad();
                    $.ajax({
                        type : "POST",  //提交方式
                        url : "/jls_zpwh/zpwhUpdate",//路径
                        data : data,//数据，这里使用的是Json格式进行传输
                        success : function(result) {
                            if (result.success) {
                                $.messager.alert("确定","修改成功","info");
                                javascript:$('#dlgZpwh').dialog('close');
                                removeLoad();
                                if($.isFunction(findZpwh)){
                                    findZpwh();
                                }
                            }else{
                                $.messager.alert("确定",result.msg,"info");
                                removeLoad();

                            }
                        },
                        error:function(){
                            removeLoad();

                        }
                    });
                }else{
                    $.messager.alert("提示", '必填项不能为空！');
                }
            };

            var bindAction=function(findZpwh){
                $("#zpwhSave").on("click",function(){
                    var zpwhId = $("#zpwhId").val();
                    if(zpwhId=="" || zpwhId==null){
                        submitZpwh(findZpwh);
                    }else{
                        updateZpwh(findZpwh);
                    }
                });
                $("#zpwhCanel").on("click",function(){
                    $("#dlgZpwh").dialog("close");
                });
            }
            return{
                show:_show
            }
        });
